import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { EArenaProcess } from "../../../../../Message/Public/EArenaProcess";
import { ObjCreate } from "../../common/ObjCreate";
import { ArenaCrossGroupMatchSchedule } from "./ArenaCrossGroupMatchSchedule";
import { ArenaCrossGroupMatchTopListPanel } from "./ArenaCrossGroupMatchTopListPanel";
import { ArenaCrossMySchedulePanel } from "./ArenaCrossMySchedulePanel";
import { MuiEvent } from "../../../../../com/mui/events/MuiEvent";
import { SArenaCrossToplists } from "../../../../../Message/Public/SArenaCrossToplists";
import { SArenaCrossGroupBattles } from "../../../../../Message/Public/SArenaCrossGroupBattles";
import { SArenaCrossBattleRecords } from "../../../../../Message/Public/SArenaCrossBattleRecords";
import { SArenaCrossGroupBattleEnd } from "../../../../../Message/Public/SArenaCrossGroupBattleEnd";
import { GTabBar } from "../../../../../com/mui/controls/GTabBar";
type int = number;
//class ArenaCrossGroupMatchPanel
    
    export  class ArenaCrossGroupMatchPanel /* flash.display.Sprite */
    {
        constructor()
        {
            this._tabBarData = new Array<any>({"label": Language.getString(44289), "name":"schedule"}, {"label": Language.getString(44290), "name":"topList"});
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            if (Cache.instance.arenaCross.arenaCrossInfo.myProcess >= EArenaProcess._EArenaGroupMatch1) 
            {
                this._tabBarData.push({"label": Language.getString(44375), "name":"mySchedule"});
            }
            this._tabBar = ObjCreate.createGTabBar(5, 0, this._tabBarData, 70, 22, this, this.onTabBarChange);
            this._tabBar.horizontalGap = 2;
            this._schedulePanel = new ArenaCrossGroupMatchSchedule();
            this._schedulePanel.groupId = this._groupId;
            this._schedulePanel.x = 0;
            this._schedulePanel.y = 22;
            this.addChild(this._schedulePanel);
            this._currentPanel = this._schedulePanel;
            this._topListPanel = new ArenaCrossGroupMatchTopListPanel();
            this._topListPanel.groupId = this._groupId;
            this._topListPanel.x = 0;
            this._topListPanel.y = 22;
            this._mySchedulePanel = new ArenaCrossMySchedulePanel();
            this._mySchedulePanel.x = 0;
            this._mySchedulePanel.y = 22;
            if (Cache.instance.arenaCross.arenaCrossInfo && Cache.instance.arenaCross.arenaCrossInfo.process == EArenaProcess._EArenaGroupMatch1 && (Cache.instance.arenaCross.isOpen || Cache.instance.arenaCross.isWillOpen)) 
            {
                if (Cache.instance.arenaCross.arenaCrossInfo.myProcess >= EArenaProcess._EArenaGroupMatch1) 
                {
                    this._tabBar.selectedIndex = 2;
                }
                else 
                {
                    this._tabBar.selectedIndex = 0;
                }
                this.onTabBarChange();
            }
            else 
            {
                this._tabBar.selectedIndex = 1;
                this.onTabBarChange();
            }
            return;
        }

        /* internal  */onTabBarChange(arg1: MuiEvent=null): void
        {
            if (this._tabBar.selectedIndex != 0) 
            {
                if (this._tabBar.selectedIndex != 1) 
                {
                    if (this._tabBar.selectedIndex == 2) 
                    {
                        if (this._currentPanel && this._currentPanel.parent) 
                        {
                            this._currentPanel.parent.removeChild(this._currentPanel);
                        }
                        this.addChild(this._mySchedulePanel);
                        this._currentPanel = this._mySchedulePanel;
                    }
                }
                else 
                {
                    if (this._currentPanel && this._currentPanel.parent) 
                    {
                        this._currentPanel.parent.removeChild(this._currentPanel);
                    }
                    this.addChild(this._topListPanel);
                    this._currentPanel = this._topListPanel;
                }
            }
            else 
            {
                if (this._currentPanel && this._currentPanel.parent) 
                {
                    this._currentPanel.parent.removeChild(this._currentPanel);
                }
                this.addChild(this._schedulePanel);
                this._currentPanel = this._schedulePanel;
            }
            return;
        }

        public set groupId(arg1: int)
        {
            this._groupId = arg1;
            this._schedulePanel.groupId = this._groupId;
            this._topListPanel.groupId = this._groupId;
            return;
        }

        public updateTopList(arg1: SArenaCrossToplists): void
        {
            this._topListPanel.updateTopList(arg1);
            return;
        }

        public updateGroupBattles(arg1: SArenaCrossGroupBattles): void
        {
            this._schedulePanel.updateGroupBattles(arg1);
            return;
        }

        public udpateMyBattles(arg1: SArenaCrossBattleRecords): void
        {
            this._mySchedulePanel.updateBattles(arg1);
            return;
        }

        public updateGroupBattleEnd(arg1: SArenaCrossGroupBattleEnd): void
        {
            this._schedulePanel.updateGroupBattleEnd(arg1);
            return;
        }

        /* internal */ /* var */_groupId: int=0;

        /* internal */ /* var */_tabBarData: Array<any>;

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_schedulePanel: ArenaCrossGroupMatchSchedule;

        /* internal */ /* var */_topListPanel: ArenaCrossGroupMatchTopListPanel;

        /* internal */ /* var */_mySchedulePanel: ArenaCrossMySchedulePanel;

        /* internal */ /* var */_currentPanel: Object /* flash.display.Sprite */;
    }
